<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>做浏览器兼容</title>
	<style type="text/css">
        #div1{
        	width:200px;height:200px;background:blue;
        }
	</style>

	<script type="text/javascript">
        window.onload = function (){
        	var oDiv = document.getElementById('div1');
        	//alert(oDiv.style.width);    获取不到，因为style规定是行间样式 
        
        	//currentStyle只兼容IE
        	//alert(oDiv.currentStyle.width);       //报错
        
        	//getComputedStyle兼容Chrome  FF(火狐)      false那个参数可以传任意的，没有意义
        	//alert(getComputedStyle(oDiv,false).width);    //200px
            

            //做个判断，兼容处理
            if(oDiv.currentStyle){            
                //IE
                alert(oDiv.currentStyle.width); 
            }else{
                //FF Chrome                    
                alert(getComputedStyle(oDiv,false).width);
            }




        };


	</script>
</head>

<body>
    
    <div id="div1"></div>
	
</body>
</html>